/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description router全局配置，如有必要可分文件抽离
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)

export const constantRoutes = [
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/carousel',
    children: [
      {
        path: 'carousel',
        name: 'Carousel',
        component: () => import('@/views/carousel/index'),
        meta: {
          title: '轮播图管理',
          icon: 'circle-notch',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/topic',
    component: Layout,
    redirect: '/topic/index',
    children: [
      {
        path: 'index',
        name: 'Topic',
        component: () => import('@/views/topic/index'),
        meta: {
          title: '专题管理',
          icon: 'pager',
        },
      },
    ],
  },
  {
    path: '/editor/:topicKey',
    hidden: true,
    props: true,
    name: 'Editor',
    component: () => import('@/views/editor'),
    meta: {
      title: '专题编辑',
    },
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: routerMode === 'history' ? publicPath : '',
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export default router
